package com.aramco.fion.model.presentation
{
	import com.aramco.fion.event.ManageTablesRecordsEvent;
	import com.aramco.fion.util.BSPAdminDataModelOO;
	import com.aramco.fion.view.dashboardAdmin.DashboardAdminViewManager;
	import com.aramco.fion.view.fion.CreateDashboardPopup;
	import com.aramco.fion.vo.Callbacks;
	
	import flash.display.DisplayObject;
	import flash.events.IEventDispatcher;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.collections.XMLListCollection;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;
	import mx.rpc.events.FaultEvent;

	[Bindable]
	public class FionDashboardManagerPresentationModel
	{
		[Dispatcher]
		public var dispatcher:IEventDispatcher;
		
		public function FionDashboardManagerPresentationModel()
		{
		}
		
		public var dataProvider:ArrayCollection;
		
		public var groupedColumns:Array;
		
		public var reportDataModel:BSPAdminDataModelOO;
		
		public var myView:DashboardAdminViewManager;
		
		[PostConstruct]
		public function loadData():void
		{
			// TODO Auto-generated method stub
			getAll();
		}
		
		[ViewAdded]
		public function viewAdded(view:DashboardAdminViewManager):void
		{
			trace('view has been addded');
			myView = view;
		}
		
		public function editRow(event:MouseEvent):void
		{
			var selectionPopup:CreateDashboardPopup = new CreateDashboardPopup();
			PopUpManager.addPopUp(selectionPopup, event.target as DisplayObject , true);
			PopUpManager.centerPopUp(selectionPopup);
		}
		
		public function getAll():void
		{
			var handler:Callbacks = new Callbacks(resultHanlder);
			var event:ManageTablesRecordsEvent = new ManageTablesRecordsEvent(ManageTablesRecordsEvent.GET_ALL_RECORDS_EVENT, handler);
			event.tableName = "ZFI_FION_DB";
			dispatcher.dispatchEvent(event);
		}
		
		private function resultHanlder(data:BSPAdminDataModelOO):void
		{
		//	trace(data);
			if(data != null)
			{
				reportDataModel = data;
				/*if(myView != null)
				{
					myView.myGrid.groupedColumns =  data.dataGridColumns;
					myView.myGrid.dataProvider =   data.repotData;
				}*/
			}
		}
	}
}